package icu.sunway.gushenBlogBackEnd.Controller;

import icu.sunway.gushenBlogBackEnd.Entity.Data.ProjectDO;
import icu.sunway.gushenBlogBackEnd.Entity.View.Project.ProjectPostVO;
import icu.sunway.gushenBlogBackEnd.Entity.View.Project.ProjectUpdateVO;
import icu.sunway.gushenBlogBackEnd.Entity.View.ResultVO;
import icu.sunway.gushenBlogBackEnd.Service.ProjectService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/project")
public class ProjectController {

    final
    ProjectService projectsService;

    public ProjectController(ProjectService projectsService) {
        this.projectsService = projectsService;
    }

    @GetMapping("/list")
    public ResultVO<List<ProjectDO>> getProjects() {
        return projectsService.getProjects();
    }

    @GetMapping("/list_page")
    public ResultVO<List<ProjectDO>> getProjectListByPage(@RequestParam int curPage,
                                                          @RequestParam int pageSize) {
        return projectsService.getProjectListByPage(curPage, pageSize);
    }

    @GetMapping("/count")
    public ResultVO<Long> getProjectCount() {
        return projectsService.getProjectCount();
    }

    @PostMapping("/add")
    public ResultVO<Boolean> addProject(@RequestBody ProjectPostVO projectPostVO) {
        return projectsService.addProject(projectPostVO);
    }

    @DeleteMapping("/delete")
    public ResultVO<Boolean> removeProject(@RequestParam String id) {
        return projectsService.removeProject(id);
    }

    @PutMapping("/update")
    public ResultVO<Boolean> updateProject(@RequestBody ProjectUpdateVO projectUpdateVO) {
        return projectsService.updateProject(projectUpdateVO);
    }
}
